<?php
    $page = $_GET['page'];

if($page=='client')
{
    require('db_connection.php');
    $userID = $_GET['userID'];
    $libraryCardNo = $_POST['libraryCardNo'];
    $lastName = $_POST['lastName'];
    $firstName = $_POST['firstName'];
    $middleName = $_POST['middleName'];
    $contactNo = $_POST['contactNo'];
    $address =$_POST['address'];
    $email = $_POST['email'];
    $schoolorg = $_POST['schoolorg'];
    $guarantor = $_POST['guarantor'];
    $libraryNo = $_COOKIE['libraryNo'];

    $sql = "SELECT * FROM tblclient";
    $result = mysql_query($sql);

    $query = "UPDATE tblclient SET libraryCardNo='$libraryCardNo',lastName='$lastName',firstName='$firstName',middleName='$middleName',address='$address',contactNo='$contactNo',email='$email',schoolorg='$schoolorg',userID='$userID',libraryNo=$libraryNo,guarantor='$guarantor',cpassword='secret',stat='activated' WHERE userID=$userID";

    $result = mysql_query($query);

    if($result){
        echo " <script>alert('Record Successfully updated!')</script> ";
        echo ("<script> document.location.href='clientprint.php?userID=$userID'</script>");
    }
    else{
        echo " <script>alert('Record Successfully Added!')</script> ";
        echo ("<script> document.location.href='client.php'</script>");
    }
    mysql_close();
}

if($page=='admin')
{

    require('db_connection.php');

    $userName = $_POST['userName'];
    $userType = $_POST['userType'];
    $libraryNo = $_POST['libraryNo'];
    $firstName = $_POST['firstName'];
    $middleName = $_POST['middleName'];
    $lastName = $_POST['lastName'];
    //$password = $_POST['password'];
    $address = $_POST['address'];
    $contactNo = $_POST['contactNo'];
    $email = $_POST['email'];
    $adminID = $_GET['adminID'];

    $sql = "SELECT * FROM tbladmin";
    $result = mysql_query($sql);

    $query = "UPDATE tbladmin SET userName='$userName', userType='$userType',lastName='$lastName',firstName='$firstName',middleName='$middleName',email='$email',contactNo='$contactNo',address='$address',libraryNo='$libraryNo',adminID='$adminID' WHERE adminID='$adminID'";

    $result = mysql_query($query);


    if($result){
        echo"<script> alert('Record successfully updated!');</script>";
        echo "<script>document.location.href='adminlist.php'</script>";
    }else{
        echo"<script> alert('Update failed!');</script>";
        echo "<script>document.location.href='adminlist.php'</script>";
    }
    mysql_close();
}
if($page=='news')
{
    require('db_connection.php');
    $libraryNo = $_POST['libraryNo'];
    //echo $libraryNo;
    $newsID = $_POST['newsID'];
    //echo $newsID;
    $title = $_POST['title'];
    //echo $title;
    $author = $_POST['author'];
    //echo $author;
    $content = $_POST['content'];
    //echo $content;
    $today = date("Y-m-d H:i.s",time());
    
    $sql = "SELECT * FROM tblnews";
    $result = mysql_query($sql);
    
    $query = "UPDATE tblnews SET newsID='$newsID',title='$title',content='$content',date='$today',libraryNo='$libraryNo' WHERE newsID='$newsID'";
    $result = mysql_query($query);

    if($result){
        echo"<script> alert('Record successfully updated!');</script>";
        echo "<script>document.location.href='newslist.php'</script>";
    }else{
        echo"<script> alert('Update failed!');</script>";
        echo "<script>document.location.href='newslist.php'</script>";
    }
    mysql_close();
}
?>
